home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_07_08 / v7n8075a.txt < prev    next >
Text File  |  1989-10-01  |  1KB  |  56 lines

  1.  
  2.  
  3. *****Listing 6*****
  4.  
  5.  
  6.  
  7.      #define DOS_IMAGE 1024
  8.      unsigned char dos_low_memory[DOS_IMAGE];
  9.  
  10.      unsigned short compute_image_checksum(start,length,copy)
  11.           unsigned char * start;
  12.           unsigned short length;
  13.           unsigned char * copy;
  14.           {
  15.            unsigned char * end = start + length;
  16.            unsigned short sum = 0;
  17.  
  18.            while(start < end)
  19.              {
  20.               if(copy)
  21.                  *copy = *start;
  22.               sum += *start++;
  23.              }
  24.            return sum;
  25.           }
  26.  
  27.      unsigned short check_image_checksum
  28.              (where,start,length,oldsum,copy)
  29.          {
  30.           unsigned short sum;
  31.           unsigned char * end = start + length;
  32.  
  33.           sum = compute_image_checksum(start,length,NULL);
  34.           if(sum == oldsum)
  35.               return 1;
  36.           fprintf(stderr,
  37.                      "Checksum error at %s: "
  38.                      "%p/%ud(0x%4x), "
  39.                      "old %ux, new %ux\n",
  40.                              where, start, length,
  41.                              oldsum, sum);
  42.  
  43.           while(start < end)
  44.              {
  45.               if(*start != *copy)
  46.                  {
  47.                   fprintf(stderr,
  48.                           " %p:  old: %02x, new: %02x\n",
  49.                           start, *copy, *start);
  50.                  }
  51.              }
  52.          }
  53.  
  54. **********
  55.  
  56.